package com.huawei.hmsdemo10086.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.huawei.hmsdemo10086.POJO.Car;
import com.huawei.hmsdemo10086.POJO.Evaluate;
import com.huawei.hmsdemo10086.R;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class EvaluateAdapter extends BaseAdapter {

    private List<Evaluate> datas = new ArrayList<Evaluate>();
    private Context context;
    private LayoutInflater layoutInflater;
    private List<Evaluate> choosed_data = new ArrayList<Evaluate>();

    public List<Evaluate> getChoosed_data() {
        return choosed_data;
    }

    public void clear_data()
    {
        choosed_data.clear();
    }

    public EvaluateAdapter(Context context, List<Evaluate> datas) {
        this.datas = datas;
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return datas.size(); //返回列表的长度
    }

    @Override
    public Evaluate getItem(int position) {
        return datas.get(position); //通过列表的位置 获得集合中的对象
    }

    @Override
    public long getItemId(int position) { // 获得集合的Item的位置
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.evaluate_node, null);//找到布局文件
            convertView.setTag(new EvaluateAdapter.ViewHolder(convertView));
        }
        initViews(getItem(position), (EvaluateAdapter.ViewHolder) convertView.getTag());
        return convertView;

    }

    private void initViews(Evaluate data, EvaluateAdapter.ViewHolder holder) {//初始化数据
        System.out.println(holder.toString());
        holder.name.setText(data.getUsername() + "");//设置Tag
        holder.evaluate.setText(data.getMessage());
        holder.timer.setText(data.getTime().toString());
    }

    protected class ViewHolder {
        private TextView name;
        private TextView evaluate;
        private TextView timer;

        public ViewHolder(View view) {
            name = (TextView) view.findViewById(R.id.name);
            evaluate = (TextView) view.findViewById(R.id.evaluate);
            timer = (TextView)view.findViewById(R.id.timer);
        }
    }
}
